{include file="public/layout" /}
<body class="bodystyle" style="overflow-y: scroll;min-width:auto;">
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page" style="min-width: auto;box-shadow:none;">
    <div class="fixed-bar">
        <div class="item-title">
            <a class="back" href="{:url('System/api_conf')}" title="返回"><i class="fa fa-angle-double-left"></i>返回</a>
            <ul class="tab-base nc-row">
                {eq name="'System@sms'|is_check_access" value="1"}
                <li><a href="{:url('System/sms')}" {if condition="'sms'==$Think.const.ACTION_NAME"}class="current"{/if}><span>短信配置</span></a></li>
                {/eq}

                {eq name="'System@sms_tpl'|is_check_access" value="1"}
                <li><a href="{:url('System/sms_tpl')}" {if condition="'sms_tpl'==$Think.const.ACTION_NAME"}class="current"{/if}><span>自定义模板</span></a></li>
                {/eq}
            </ul>
        </div>
    </div>
    <form class="form-horizontal" id="postSmsForm" method="post">
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit">
                    <label for="sms_type">短信平台</label>
                </dt>
                <dd class="opt">
                    <label class="curpoin"><input type="radio" name="sms_type" value="1" onclick="changeSmsType(this);" {if condition="empty($sms.sms_type) || $sms.sms_type eq 1"}checked="checked"{/if}>阿里云短信</label>
                    &nbsp;&nbsp;
                    <label class="curpoin"><input type="radio" name="sms_type" value="2" onclick="changeSmsType(this);" {if condition="isset($sms.sms_type) && $sms.sms_type eq 2"}checked="checked"{/if}>腾讯云短信</label>
                    <input type="hidden" id="old_sms_type" value="{if condition="empty($sms.sms_type) || $sms.sms_type eq 1"}1{else /}2{/if}">
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row" id="sms_appkey_1" style="display: {if condition="!isset($sms.sms_type) || $sms.sms_type eq 1"} block{else /}none{/if};" >
                <dt class="tit">
                    <em>*</em>
                    <label for="sms_appkey">平台appkey</label>
                </dt>
                <dd class="opt">
                    <input id="sms_appkey" name="sms_appkey" value="{$sms.sms_appkey|default=''}" class="input-txt" type="text"/>
                    <p class="notic">短信平台配置appkey</p>
                </dd>
            </dl>
            <dl class="row" id="sms_secretkey_1" style="display: {if condition="!isset($sms.sms_type) || $sms.sms_type eq 1"} block{else /}none{/if};">
                <dt class="tit">
                    <em>*</em>
                    <label for="sms_secretkey">平台secretKey</label>
                </dt>
                <dd class="opt">
                    <input id="sms_secretkey" name="sms_secretkey" value="{$sms.sms_secretkey|default=''}" class="input-txt" type="text"/>
                    <p class="notic">短信平台配置secretKey</p>
                </dd>
            </dl>

            <dl class="row" id="sms_appkey_2" style="display: {if condition="!isset($sms.sms_type) || $sms.sms_type eq 2"} block{else /}none{/if};">
                <dt class="tit">
                    <em>*</em>
                    <label for="sms_appkey_tx">平台appkey</label>
                </dt>
                <dd class="opt">
                    <input id="sms_appkey_tx" name="sms_appkey_tx" value="{$sms.sms_appkey_tx|default=''}" class="input-txt" type="text"/>
                    <p class="notic">短信平台配置appkey</p>
                </dd>
            </dl>
            <dl class="row" id="sms_secretkey_2" style="display: {if condition="!isset($sms.sms_type) || $sms.sms_type eq 2"} block{else /}none{/if};">
                <dt class="tit">
                    <em>*</em>
                    <label for="sms_appid_tx">平台appid</label>
                </dt>
                <dd class="opt">
                    <input id="sms_appid_tx" name="sms_appid_tx" value="{$sms.sms_appid_tx|default=''}" class="input-txt" type="text"/>
                    <p class="notic">短信平台配置appid</p>
                </dd>
            </dl>

            <dl class="row">
                <dt class="tit"><em>*</em>接收手机号</dt>
                <dd class="opt">
                    <input value="{$sms.sms_test_mobile|default=''}" name="sms_test_mobile" id="sms_test_mobile" class="input-txt" type="text">
                    <input value="测试发送" class="input-btn" onclick="sendMobile();" type="button">
                    <p class="notic"></p>
                </dd>
            </dl>
            <!-- <dl class="row">
                <dt class="tit">短信提醒</dt>
                <dd class="opt">
                    <ul class="nc-row ncap-waybill-list">
                        <li style="width: 100%;">
                            <label class="label">
                                <input class="check" type="checkbox" name="sms_shop_order_pay" {if condition="!empty($sms.sms_shop_order_pay)"} value="1" checked="checked" {/if}><span onmouseover="layer_tips = layer.tips('对管理员发送短信提醒', this, {time:100000});" onmouseout="layer.close(layer_tips);">订单付款</span>
                            </label>
                            &nbsp; &nbsp;
                            <label class="label">
                                <input class="check" type="checkbox" name="sms_shop_order_send" {if condition="!empty($sms.sms_shop_order_send)"} value="1" checked="checked" {/if}><span onmouseover="layer_tips = layer.tips('对用户发送短信提醒', this, {time:100000});" onmouseout="layer.close(layer_tips);">订单发货</span>
                            </label>
                        </li>
                    </ul>
                </dd>
            </dl> -->
            <dl class="row">
                <div class="bot" style="padding-bottom:0px;">
                    <a href="JavaScript:void(0);" onclick="submit_sms();" class="ncap-btn-big ncap-btn-green">确认提交</a>
                    &nbsp;<a href="JavaScript:void(0);" onclick="openArticle()" style="font-size: 12px;padding-left: 10px;position:absolute;top: 30px">不会配置？</a>
                </div>
            </dl>
        </div>
    </form>
</div>
<script type="text/javascript">
    var parentObj = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    function submit_sms(){
        var sms_type = $("#old_sms_type").val();
        if (sms_type == 1) {
            if ($('#postSmsForm input[name="sms_appkey"]').val() == '') {
                showErrorMsg('请填写短信平台[appkey]！');
                $('#postSmsForm input[name=sms_appkey]').focus();
                return false;
            }
            if ($('#postSmsForm input[name="sms_secretkey"]').val() == '') {
                showErrorMsg('请填写短信平台[secretKey]！');
                $('#postSmsForm input[name=sms_secretkey]').focus();
                return false;
            }
        }else{
            if ($('#postSmsForm input[name="sms_appkey_tx"]').val() == '') {
                showErrorMsg('请填写短信平台[appkey]！');
                $('#postSmsForm input[name=sms_appkey_tx]').focus();
                return false;
            }
            if ($('#postSmsForm input[name="sms_appid_tx"]').val() == '') {
                showErrorMsg('请填写短信平台[appid]！');
                $('#postSmsForm input[name=sms_appid_tx]').focus();
                return false;
            }
        }

        var mobile = $('#sms_test_mobile').val();
        if (mobile == '') {
            showErrorMsg('接收的手机号码不能为空！');
            $('#postSmsForm input[name=sms_test_mobile]').focus();
            return false;
        }

        layer_loading("正在处理");
        $.ajax({
            url: "{:url('System/sms', ['_ajax'=>1])}",
            type: 'POST',
            dataType: 'JSON',
            data: $('#postSmsForm').serialize(),
            success: function(res){
                layer.closeAll();
                if (1 == res.code) {
                    layer.msg(res.msg, {shade: 0.3, time: 1000}, function(){
                        window.location.reload();
                    });
                } else {
                    var icon = 5;
                    try{
                        if (res.data.icon) {
                            icon = res.data.icon;
                        }
                    }catch(e){}
                    showErrorAlert(res.msg, icon);
                }
            },
            error: function(e){
                layer.closeAll();
                showErrorAlert(e.responseText);
            }
        });
    }

    function sendMobile() {
        var sms_type = $("#old_sms_type").val();
        if (sms_type == 1) {
            if ($('#postSmsForm input[name="sms_appkey"]').val() == '') {
                showErrorMsg('请填写短信平台[appkey]！');
                $('#postSmsForm input[name=sms_appkey]').focus();
                return false;
            }
            if ($('#postSmsForm input[name="sms_secretkey"]').val() == '') {
                showErrorMsg('请填写短信平台[secretKey]！');
                $('#postSmsForm input[name=sms_secretkey]').focus();
                return false;
            }
        }else{
            if ($('#postSmsForm input[name="sms_appkey_tx"]').val() == '') {
                showErrorMsg('请填写短信平台[appkey]！');
                $('#postSmsForm input[name=sms_appkey_tx]').focus();
                return false;
            }
            if ($('#postSmsForm input[name="sms_appid_tx"]').val() == '') {
                showErrorMsg('请填写短信平台[appid]！');
                $('#postSmsForm input[name=sms_appid_tx]').focus();
                return false;
            }
        }
        var mobile = $('#sms_test_mobile').val();
        if (mobile == '') {
            showErrorMsg('接收的手机号码不能为空！');
            $('#postSmsForm input[name=sms_test_mobile]').focus();
            return false;
        }
        var loading = layer_loading('发送中');
        $.ajax({
            type: "post",
            data: $('#postSmsForm').serialize(),
            dataType: 'json',
            url: "{:url('System/send_mobile')}",
            success: function (res) {
                layer.closeAll();
                if (res.code == 1) {
                    layer.msg('发送成功', {icon: 1, time:1000});
                } else {
                    layer.msg(res.msg, {icon: 2, time: 1000});
                }
            },
            error: function(){
                layer.closeAll();
                showErrorAlert(e.responseText);
            }
        })
    }

    function changeSmsType(obj) {
        var new_sms_type = $("input[name=sms_type]:checked").val();
        var old_sms_type = $("#old_sms_type").val();
        if (new_sms_type) {
            $("#sms_appkey_"+old_sms_type).hide();
            $("#sms_secretkey_"+old_sms_type).hide();
            $("#sms_appkey_"+new_sms_type).show();
            $("#sms_secretkey_"+new_sms_type).show();
            $("#old_sms_type").val(new_sms_type);
        }
    }

    function openArticle() {
        var new_sms_type = $("input[name=sms_type]:checked").val();
        var aid = new_sms_type == 1?8754:11143;
        click_to_eyou_1575506523('https://www.eyoucms.com/plus/view.php?aid='+aid,'短信配置教程');
    }
</script> 

{include file="public/footer" /}